package pl.dmcs.grails.planner

import javax.servlet.http.HttpServletRequest;

import com.dhtmlx.planner.DHXPlanner;
import com.dhtmlx.planner.DHXSkin;
import com.dhtmlx.planner.data.DHXDataFormat;
import com.dhtmlx.planner.extensions.DHXExtension;


class PlannerService {
    def getPlanner(boolean readonly, String pathToPlannerScripts, String processEventsURL) {
        DHXPlanner p = new DHXPlanner(pathToPlannerScripts, DHXSkin.TERRACE);
        p.setWidth(900);
        p.setHeight(700);
        p.setInitialDate(Calendar.getInstance());
        p.config.setFirstHour(7);
        p.config.setLastHour(21);
        p.load(processEventsURL, DHXDataFormat.JSON);//sets the function that will provide loading  data
        p.data.dataprocessor.setURL(processEventsURL);
        
        p.extensions.add(DHXExtension.RECURRING);
        p.config.setRepeatPrecise(true);
        
        if (readonly) {
            p.extensions.add(DHXExtension.READONLY);
            p.config.setReadonly(true);
        }
        return p;
    }
}
